#include "EditBox.h"

EditBox::EditBox()
{
	m_hf = CreateFont(15, 0, 0, 0, FW_NORMAL, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Arial");
}
EditBox::~EditBox()
{

}
bool EditBox::Setup(HWND a_hWnd, HINSTANCE a_hInst, int a_xPos, int a_yPos, int a_width, int a_height)
{
	m_hWnd = CreateWindowEx(WS_EX_CONTROLPARENT, "EDIT", NULL, WS_CHILD | WS_TABSTOP | WS_VISIBLE | ES_CENTER, a_xPos, a_yPos, a_width, a_height, a_hWnd, NULL, a_hInst, NULL);
	if(m_hWnd == NULL)
	{
		return false;
	}
	SendMessage(m_hWnd, WM_SETFONT, (WPARAM)m_hf, (LPARAM)true);
	SetParent(m_hWnd, a_hWnd);
	
	UpdateWindow(m_hWnd);
	ShowWindow(m_hWnd, SW_SHOW);

	return true;
}
int EditBox::GetInt()
{
	char buffer[512];
	SendMessage(m_hWnd, WM_GETTEXT, (WPARAM)512, (LPARAM)&buffer);
	return atoi(buffer); 
}
char* EditBox::GetString()
{
	char buffer[512];
	SendMessage(m_hWnd, WM_GETTEXT, (WPARAM)512, (LPARAM)&buffer);
	return buffer;
}
void EditBox::SetText(char* a_pLabel)
{
	SendMessage(m_hWnd, WM_SETTEXT, 0, (LPARAM)a_pLabel);
}

HWND EditBox::GetHWND() const
{
	return m_hWnd;
}
